package com.woniuxy.java106crm.controller;

import com.woniuxy.java106crm.annotation.RequireMethod;
import com.woniuxy.java106crm.entity.DataDictionary;
import com.woniuxy.java106crm.request.ResponseResult;
import com.woniuxy.java106crm.service.DictionaryService;
import com.woniuxy.java106crm.vo.GradeVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 数据字典表的管理类
 */
@Api(tags = "数据字典管理模块API文档")
@Slf4j
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {
    //service注入
    @Resource
    private DictionaryService dictionaryService;


    //根据类型查询数据字典表
    @RequireMethod("根据类型查询数据字典表")
    @GetMapping("/findDataDictByType")
    public ResponseResult<List<DataDictionary>> findDataDictByType(@RequestParam String type){
//        log.debug("传过来的参数是：{}",type);
        return new ResponseResult<>(ResponseResult.OK,dictionaryService.findDataDictByType(type.trim()));
    }

    //添加基础数据
    @RequireMethod("添加基础数据")
    @PostMapping("/addData")
    public ResponseResult<Boolean> addData(@RequestBody DataDictionary dataDictionary){
        log.debug(dataDictionary.toString());
        return new ResponseResult<>(ResponseResult.OK,dictionaryService.addData(dataDictionary));
    }
    //修改基础数据
    @RequireMethod("修改基础数据")
    @PutMapping("/editData")
    public ResponseResult<Boolean> editData(@RequestBody DataDictionary dataDictionary){
//        log.debug(dataDictionary.toString());
        return new ResponseResult<>(ResponseResult.OK,dictionaryService.editData(dataDictionary));
    }
    //删除基础数据
    @RequireMethod("删除基础数据")
    @DeleteMapping("/delData/{id}")
    public ResponseResult<Boolean> delData(@PathVariable("id") Integer id){
//        log.debug("传过来的id值为：{}",id);
        return new ResponseResult<>(ResponseResult.OK,dictionaryService.delData(id));
    }
    //批量删除
    @RequireMethod("批量删除基础数据")
    @DeleteMapping("/putchDel/{ids}")
    public ResponseResult<Boolean> putchDel(@PathVariable("ids") String ids){
//        log.debug("传过来的id值为：{}",ids);
        return new ResponseResult<>(ResponseResult.OK,dictionaryService.putchDel(ids));
    }

    //查询所有客户等级
    @GetMapping("/getGrade")
    public ResponseResult<List<GradeVo>> getGrade(){
        return new ResponseResult<>(ResponseResult.OK,dictionaryService.getGrade());
    }
}
